package com.fzhucc.modules.pms.repository;

import com.fzhucc.modules.pms.domain.Project;
import com.fzhucc.modules.pms.domain.ProjectSmall;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author Woolsen
 */
public interface ProjectSmallRepository extends JpaRepository<ProjectSmall, String>, JpaSpecificationExecutor<ProjectSmall> {

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE level=:level and is_show=1 and del_flag=0 and (project_name LIKE :text  or race_domain LIKE :text )")
    Page<ProjectSmall> findAllXcxWithOutAreaOrg(int level,String text,Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE level=:level and is_show=1 and del_flag=0 and org_area=:area and (project_name LIKE :text  or race_domain LIKE :text )")
    Page<ProjectSmall> findAllXcx(int level,String text,String area,Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE level=:level and is_show=1 and del_flag=0 and org_area=:area ")
    Page<ProjectSmall> findAllXcxWithOutLikeText(int level,String area,Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE is_show=1 and del_flag=0 and org_area=:area")
    Page<ProjectSmall> findAllXcxWithOutLikeTextWithOutLevel(String area, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE is_show=1 and del_flag=0 and org_area=:area and (project_name LIKE :text  or race_domain LIKE :text )")
    Page<ProjectSmall> findAllXcxWithOutLevel(String text,String area,Pageable pageable);


    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE is_show=1 and del_flag=0")
    Page<ProjectSmall> findAllXcxWithOutLikeTextWithOutLevelWithOutOrgArea(Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE level=:level and is_show=1 and del_flag=0")
    Page<ProjectSmall> findAllXcxWithOutLikeTextWithOutOrgArea(int level,Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM pms_project WHERE is_show=1 and del_flag=0 and (project_name LIKE :text  or race_domain LIKE :text )")
    Page<ProjectSmall> findAllXcxWithOutLevelWithOutOrgArea(String text,Pageable pageable);

}